package com.dd.mall.protal.web.service.impl;

import com.dd.common.dao.cms.SubjectDao;
import com.dd.common.dao.pms.ProductCategoryDao;
import com.dd.common.entity.cms.SubjectVo;
import com.dd.common.entity.pms.ProductCategoryVo;
import com.dd.common.entity.view.CommonPage;
import com.dd.mall.protal.web.service.IndexService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.List;

/**
 * 首页服务类
 */
@Service
public class IndexServiceImpl implements IndexService {

    @Autowired
    private ProductCategoryDao productCategoryDao;

    @Autowired
    private SubjectDao subjectDao;


    @Override
    public List<ProductCategoryVo> queryProductCategoryByParentId(int id) {
        return productCategoryDao.selectByParentId(id);
    }


    @Override
    public CommonPage<List<SubjectVo>> querySubjectForPage(Long cateId, Integer pageSize, Integer pageNum) {
        Page page = PageHelper.startPage(pageNum,pageSize);
        List<SubjectVo> subjectVoList = subjectDao.selectForPage(cateId);
        CommonPage<List<SubjectVo>> commonPage = CommonPage.restPage(Collections.singletonList(subjectVoList));
        return commonPage;
    }
}
